/**
 * Created by admin on 2016/7/27.
 */
//var bath="onlineweb.boxuegu.com:58000";
$(function () {
    //测试环境只能点击ID为1
    //4----------------------
    //侧栏菜单
    var sidler='<div class="courseNav">'+
        '<ul class="subjectLists" id="sy7">'+
        '{{each items.Top_data}}' +
        '{{if $index<8}}'+
        '        <li>'+
        '            <div class="courseList-nav"><span>{{$value.protype_name}}</span><i class="iconfont icon-left"></i>'+
        '            </div>'+
        '            <div class="subjectLists-childrenBox">'+
        '                {{each $value.rel_profession as $proValue}}' +
        '                <div class="courseList-content">'+
        '                    <h2>{{$proValue.pro_name}}</h2>'+
        '                    <ul class="courseList-content-items">' +
        '                     {{each items.Two_data as $courseValue}}'+
        '                     {{if $proValue.id == $courseValue.profession_id}}' +
        '                     <li>{{#indexHref($courseValue.type,$courseValue.id)}}' +
        '                         {{if $index == 0}}' +
        '                         <span class="carName_bold">{{$courseValue.course_name}}</span>' +
        '                         {{else}}' +
        '                         <span>{{$courseValue.course_name}}</span>' +
        '                         {{/if}}' +
        '                         </a>' +
        '                     </li>'+
        '                     {{/if}}' +
        '                     {{/each}}'+
        '                    </ul>'+
        '                </div>'+
        '                {{/each}}'+
        '            </div>'+
        '        </li>'+
        '{{/if}}' +
        '{{/each}}'+
        '	</ul>'+
        '</div>';
    template.helper('href', function (num) {
        if (num != "") {
            return '' + bath + '/web/courseDetail/' + num;
        } else {
            return 'javascript:;';
        }
    });
    template.helper('menuBenefit',function(tags){
        var sortArray=[],array=[];
        function tagsObject(courseId,name,isBold,url){
            this.id=courseId;
            this.name=name;
            this.isBold=isBold;
            this.url=url;
        }
        if(tags!="" && tags!=null){
            tags=tags.split("|");
            for(var j=0;j<tags.length;j++){
                sortArray.push(tags[j].split(","));
            }
            for(var k=0;k<sortArray.length;k++){
                array.push(new tagsObject(sortArray[k][0],sortArray[k][1],sortArray[k][2],sortArray[k][3]));
            }
            array.sort(function(a,c){
                return c.id- a.id;
            });
            var str='';
            for(var i=0;i<array.length;i++){
                if(array[i]["isBold"]!='N'){
                    str+='<li>' +
                        '<a href="'+array[i]["url"]+'" target="_blank"><span class="carName_bold">' +
                        ''+array[i]["name"]+'</span></a></li>';
                }else{
                    str+='<li>' +
                        '<a href="'+array[i]["url"]+'" target="_blank"><span>' +
                        ''+array[i]["name"]+'</span></a></li>';
                }
            }
            return str;
        }
    });
    function get_cookie(Name) {
        var search = Name + "="//查询检索的值
        var returnvalue = "";//返回值
        if (document.cookie.length > 0) {
            sd = document.cookie.indexOf(search);
            if (sd!= -1) {
                sd += search.length;
                end = document.cookie.indexOf(";", sd);
                if (end == -1)
                    end = document.cookie.length;
                returnvalue=unescape(document.cookie.substring(sd, end))
            }
        }
        return returnvalue;
    }
    // alert(get_cookie("first_login"));
    if(get_cookie("first_login") == "1"){
        $("#oldModalBack").show();
        $("#old").show();
    }else{

    }
    $(".pathLeft .path a").each(function () {
        if ($(this).text() == "首页") {
            $(this).addClass("select");
        } else {
            $(this).removeClass("select");
        }
    });
    //首页的左侧菜单导航{
    /**
     * courseType  0:职业课  1:微课
     */
    function subjectNav(){
        RequestService("/index/getIndexSubjectAndCourse","GET",{},function(data){
            $(".bannerNav_left").html(template.compile(sidler)({items:data}));
            $(".courseList-content-items li").on("click",function(){
                var indexId=$(this).find('a').attr("data-indexId");
                RequestService("/banner/updateClickCount","POST",{id:indexId,_token:$('input[name=_token]').val()},function(){})
            })
        })
    }
    subjectNav();
    /*轮播图*/
    $(function () {
        RequestService("/banner/getBannerList", "GET", "", function (data) {
            if(data.length <= 1){
                $(".left,.right").hide();
            }
            $("#slider").html(template('sliderTpl',{items:data}));
            $('#selector').html(template('selectorTpl',{items:data}));
            init();
            $("#slider li").on("click",function(){
                var indexId=$(this).attr("data-indexId");
                RequestService("/banner/updateClickCount","POST",{id:indexId,_token:$('input[name=_token]').val()},function(){})
            })
        });
    });
    /*--------------------------培训课程开始---------------------------------------------*/
    RequestService("/courseIntroduction/getCourseIntroductionList","GET",null,function(data){
        $(".subject-entery").html(template('subjects',{items:data}));
        $(".subject-entery a").on("click",function(){
            var indexId=$(this).attr("data-indexId");
            RequestService("/banner/updateClickCount","POST",{id:indexId,_token:$('input[name=_token]').val()},function(){})
        })
    });
    /*----------------------------培训课程结束-------------------------------------------*/

    //电影
    employmentClass();
    //会员
    member();
    //剧集
    sitcom();
    //综艺
    variety();
    //培训课堂
    microCourse();

    /*直播*/
    RequestService("/RecommendedLivebroadcast/listByIndex", "GET", null, function (data) {
        var boxContent = $(".slideBox .boxContent");
        boxContent.html(template('studentStory',{item: data}));
        setTimeout(function () {
            jQuery(".slide-box").slide({mainCell: ".slideBox ul", autoPage: true, effect: "leftLoop", autoPlay: true, vis: 5, easing: "swing", interTime: '4000', delayTime: '300'});
            $(".boxContent li .rr").off().on("click", function () {
                var storyId = $(this).parent().attr("data-storyId");
                window.open(bath + '/web/storyDetail/' + storyId);
            })
        }, 1000)
    },false);

});

//首页双十二入口
var futureTime = new Date("2018/02/09 23:59:59").getTime();
var nowTime = new Date().getTime();
if(nowTime>futureTime){

}else{
    setTimeout(function(){
        $(".shuangshier").css("display","block").animate({
            bottom:"0"
        },1000);
    },"2000");
    $(".shuangshierClose").click(function(){
        $(".shuangshier").css("display","none");
    });
}
function init() {
    var $sliders = $('#slider li');
    var $selector = $('#selector');
    var $selectors = $('#selector span');
    var $left = $('.bannerNav .left');
    var $right = $('.bannerNav .right');
    //自动切换
    var step =0;

    function autoChange() {
        $sliders = $('#slider li');
        $selector = $('#selector');
        $selectors = $('#selector span');
        step++;
        if (step === $sliders.length) {
            step = 0;
        };
        $sliders.eq(step).fadeIn(800).siblings().fadeOut(800);
        $selectors.eq(step).addClass('cur').siblings().removeClass('cur');
    }

    var timer = window.setInterval(autoChange, 5000);

    //点击圆圈切换
    $selector.on('click', function (e) {
        var $target = $(e.target);
        if ($target.get(0).tagName === 'SPAN') {
            window.clearInterval(timer);
            $target.addClass('cur').siblings().removeClass('cur');
            step = $target.index();
            $sliders.eq(step).fadeIn(800).siblings().fadeOut(800);
            timer = window.setInterval(autoChange, 5000);
        }
    });

    //点击左右按钮切换
    $left.on('click', function () {
        window.clearInterval(timer);
        step--;
        if (step < 0) {
            step = $sliders.length - 1;
            $sliders.eq(step).fadeIn(800).siblings().fadeOut(800);
            $selectors.eq(step).addClass('cur').siblings().removeClass('cur');
        } else {
            $sliders.eq(step).fadeIn(800).siblings().fadeOut(800);
            $selectors.eq(step).addClass('cur').siblings().removeClass('cur');
        }
        timer = window.setInterval(autoChange, 5000);
    })
    $right.on('click', function () {
        window.clearInterval(timer);
        step++;
        if (step > $sliders.length - 1) {
            step = 0;
            $sliders.eq(step).fadeIn(800).siblings().fadeOut(800);
            $selectors.eq(step).addClass('cur').siblings().removeClass('cur');
        } else {
            $sliders.eq(step).fadeIn(800).siblings().fadeOut(800);
            $selectors.eq(step).addClass('cur').siblings().removeClass('cur');
        }
        timer = window.setInterval(autoChange, 5000);
    })
}
//电影
function employmentClass(){
    RequestService("/index/getIndexCareerCourse/protype_id/3","GET","",function(data){
        $("#Film").html(template('employmentTpl',{item:data}));
        $("#Film li").on("click",function(){
            var indexId=$(this).find('div').find('a').attr("data-indexId");
            RequestService("/banner/updateClickCount","POST",{id:indexId,_token:$('input[name=_token]').val()},function(){})
        })
    })
}
//会员
function member(){
    RequestService("/index/getIndexCareerCourse/protype_id/4","GET","",function(data){
        $("#Member").html(template('employmentTplMember',{item:data}));
        $("#Member li").on("click",function(){
            var indexId=$(this).find('div').find('a').attr("data-indexId");
            RequestService("/banner/updateClickCount","POST",{id:indexId,_token:$('input[name=_token]').val()},function(){})
        })
    })
}
//剧集
function sitcom(){
    RequestService("/index/selectSitcom/protype_id/1","GET","",function(data){
        $("#tabFirst1").html(template('sitcomNav',{item:data}));
        $("#log1").html(template('sitcom',{courseLists:data}));
        $("#log1 div div").on("click",function(){
            var indexId=$(this).find('a').attr("data-indexId");
            RequestService("/banner/updateClickCount","POST",{id:indexId,_token:$('input[name=_token]').val()},function(){})
        })
        $("#tabFirst1 li").click(function(){
            $(this).addClass("select").siblings().removeClass("select");
            $("#log1 .content").eq($(this).index()).show().siblings().hide();
        });
        $("#tabFirst1 li").eq(0).trigger("click");
    });
}
//综艺
function variety(){
    RequestService("/index/selectSitcom/protype_id/2","GET","",function(data){
        $("#tabFirst2").html(template('varietyNav',{item:data}));
        $("#log2").html(template('variety',{courseLists:data}));
        $("#log2 div div").on("click",function(){
            var indexId=$(this).find('a').attr("data-indexId");
            RequestService("/banner/updateClickCount","POST",{id:indexId,_token:$('input[name=_token]').val()},function(){})
        })
        $("#tabFirst2 li").click(function(){
            $(this).addClass("select").siblings().removeClass("select");
            $("#log2 .content").eq($(this).index()).show().siblings().hide();
        });
        $("#tabFirst2 li").eq(0).trigger("click");
    });
}


//培训课堂
function microCourse(){
    RequestService("/index/selectSitcom/protype_id/15","GET","",function(data){
        $("#tabFirst").html(template('strcourseNav',{item:data}));
        $("#log").html(template('strcourse',{courseLists:data}));
        $("#log div div").on("click",function(){
            var indexId=$(this).find('a').attr("data-indexId");
            RequestService("/banner/updateClickCount","POST",{id:indexId,_token:$('input[name=_token]').val()},function(){})
        })
        $("#tabFirst li").click(function(){
            $(this).addClass("select").siblings().removeClass("select");
            $("#log .content").eq($(this).index()).show().siblings().hide();
        });
        $("#tabFirst li").eq(0).trigger("click");
    });
}


headerMeta(1,null);





